//
//  ChangePassWordVC.m
//  jinwang
//
//  Created by jzb on 2018/3/13.
//  Copyright © 2018年 jzb. All rights reserved.
//

#import "ChangePassWordVC.h"

@interface ChangePassWordVC ()

@property (weak, nonatomic) IBOutlet UITextField *YuanPWTF;

@property (weak, nonatomic) IBOutlet UITextField *NewPWTF;

@property (weak, nonatomic) IBOutlet UITextField *QRNewPWTF;

@end

@implementation ChangePassWordVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"修改密码";
    self.view.backgroundColor = [UIColor whiteColor];
    
}

- (IBAction)QRBtnOnclick:(UIButton *)sender {
    
    //确认
    if (kStringIsEmpty(self.YuanPWTF.text)) {
        [self showBottomMessag:@"请输入原密码"];
        return;
    }else if (self.YuanPWTF.text.length < 6) {
        [self showCenterMessage:@"原密码长度为六位"];
        return;
    }else if (kStringIsEmpty(self.NewPWTF.text)) {
        [self showBottomMessag:@"请输入新密码"];
        return;
    }else if (self.NewPWTF.text.length < 6) {
        [self showCenterMessage:@"新密码长度为六位"];
        return;
    }else if (kStringIsEmpty(self.QRNewPWTF.text)) {
        [self showCenterMessage:@"请确认新密码"];
        return;
    }else if (self.QRNewPWTF.text.length < 6) {
        [self showCenterMessage:@"确认密码长度为六位"];
        return;
    }
    
    [[DDNetworkManagerDate makeUrl_editPassword_with_token:k_user_token old_password:self.YuanPWTF.text new_password:self.NewPWTF.text confirm_password:self.QRNewPWTF.text] post_RequestFinshSuccess:^(id responseObject) {
        if ([self requestFinshCode:responseObject isShowMessage:YES] == 1) {
            [kUserDefaults setObject:self.YuanPWTF.text forKey:@"user_pwd"];
            [self goBack];
        }
    } failure:^(id errorObject) {
        [self showBottomMessag:@"网络请求失败"];
    }];
}


#pragma mark -UITextFieldDelegate
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    //限制手机号长度
    if ([textField isEqual:self.YuanPWTF]) {
        NSUInteger length = textField.text.length + string.length - range.length;
        if (length <= 6) {
            return YES;
        }else{
            [self.YuanPWTF shakeWithShakeDirection:ShakingDirectionHorizontal];
            return NO;
        }
    }else if ([textField isEqual:self.NewPWTF]) {
        NSUInteger length = textField.text.length + string.length - range.length;
        if (length <= 6) {
            return YES;
        }else{
            [self.NewPWTF shakeWithShakeDirection:ShakingDirectionHorizontal];
            return NO;
        }
    }else if ([textField isEqual:self.QRNewPWTF]) {
        NSUInteger length = textField.text.length + string.length - range.length;
        if (length <= 6) {
            return YES;
        }else{
            [self.QRNewPWTF shakeWithShakeDirection:ShakingDirectionHorizontal];
            return NO;
        }
    }
    else{
        return YES;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
